package licode.unisop.client.controller;

import licode.unisop.client.utils.SopResult;
import licode.unisop.client.visit.AssetRelQueryVisit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 定义统一认证平台中心领域相关接口
 *
 * @author licode
 */
@Slf4j
@RestController
@RequestMapping("/uni-api/v1/asset")
public class SopAssetQueryController {
    @Resource
    private AssetRelQueryVisit assetRelQueryVisit;

    /**
     * 分页查询平台资源信息
     */
    @RequestMapping(value = "/query/page", method = RequestMethod.POST)
    public SopResult<Object> queryPage(@RequestBody Map<String, Object> req) {
        return SopResult.of(assetRelQueryVisit.queryPage(req));
    }

    /**
     * 分页查询平台可移动资源信息
     */
    @RequestMapping(value = "/query/move/page", method = RequestMethod.POST)
    public SopResult<Object> queryMovePage(@RequestBody Map<String, Object> req) {
        return SopResult.of(assetRelQueryVisit.queryMovePage(req));
    }

    /**
     * 按层级获取指定类型的资源
     */
    @RequestMapping(value = "/query/level/all", method = RequestMethod.POST)
    public SopResult<Object> queryAllByLevel(@RequestBody Map<String, Object> req) {
        return SopResult.of(assetRelQueryVisit.queryAllByLevel(req));
    }

    /**
     * 按层级分页查询资源信息，必须传入父资源ID，如果父资源ID为空，则查询顶层所有资源
     */
    @RequestMapping(value = "/query/level/page", method = RequestMethod.POST)
    public SopResult<Object> queryPageByLevel(@RequestBody Map<String, Object> req) {
        return SopResult.of(assetRelQueryVisit.queryPageByLevel(req));
    }

    /**
     * 分页查询指定资源拥有的所有资源信息，比如查询指定分组下所有的权限信息
     */
    @RequestMapping(value = "/relation/of-holder/page", method = RequestMethod.POST)
    public SopResult<Object> queryAssetsOfHolderPage(@RequestBody Map<String, Object> req) {
        return SopResult.of(assetRelQueryVisit.queryAssetsOfHolderPage(req));
    }

    /**
     * 分页查询拥有指定资源的所有资源信息，比如查询拥有指定权限的所有分组信息
     */
    @RequestMapping(value = "/relation/to-holders/page", method = RequestMethod.POST)
    public SopResult<Object> queryHoldersOfAssetPage(@RequestBody Map<String, Object> req) {
        return SopResult.of(assetRelQueryVisit.queryHoldersOfAssetPage(req));
    }

    /**
     * 读取资源属性
     */
    @RequestMapping(value = "/query/attribute/load", method = RequestMethod.POST)
    public SopResult<Map<String, Object>> loadAttributesOfAsset(@RequestBody Map<String, Object> req) {
        return SopResult.of(assetRelQueryVisit.loadAttributesOfAsset(req));
    }
}
